//Copyright 2011 New York City 3D Community

//This file is part of New York City 3D.

//New York City 3D is free software: youf can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//New York City 3D is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with New York City 3D.  If not, see <http://www.gnu.org/licenses/>.

package nyc3d.street;

import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
 *
 * @author A Walk/Don't Walk signal intended for pedestrian use when crossing a street.
 */
public class PedestrianWalkSignal {
    String name;
    Node node, parentNode;
    Spatial spatial;
    Material material;
    private PedestrianWalkSignalSide sides[];
    TrafficLight controllingSignal;
    public enum Type{TOWARD_TOWARD, AWAY_AWAY, TOWARD_AWAY, AWAY_TOWARD, TWO_ONE_AWAY};
    public enum Model{SEPARATE, ATTACHED};
    private Type type;
    private Model model;

    public PedestrianWalkSignal(String name, Type type, Model model, AssetManager assetManager, Vector3f translation, Vector3f rotation, Vector3f scale, Node parentNode){
        this.name = name;
        this.parentNode = parentNode;
        this.type = type;
        this.model = model;

        switch(model){
            case SEPARATE:
                spatial = assetManager.loadModel("Scenes/PedestrianSignal/PedestrianSignal.j3o");
                break;
            case ATTACHED:
                spatial = assetManager.loadModel("Scenes/PedestrianSignalLight/PedestrianSignalLight.j3o");
                break;
        }
        spatial.setShadowMode(ShadowMode.CastAndReceive);

        material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        material.setFloat("Shininess", 100f);
        spatial.setMaterial(material);

        node = new Node(name);
        node.setLocalTranslation(translation);
        node.rotate(rotation.x, rotation.y, rotation.z);
        node.scale(scale.x, scale.y, scale.z);
        node.attachChild(spatial);

        switch(model){
            case SEPARATE:
                switch(type){
                    case AWAY_AWAY:
                        sides = new PedestrianWalkSignalSide[2];
                        sides[0] = new PedestrianWalkSignalSide(PedestrianWalkSignalSide.Type.MAIN, PedestrianWalkSignalSide.Orientation.AWAY, assetManager, new Vector3f(.005f, 6.08f, -1.315f), rotation, this, false);
                        sides[1] = new PedestrianWalkSignalSide(PedestrianWalkSignalSide.Type.SECONDARY, PedestrianWalkSignalSide.Orientation.AWAY, assetManager, new Vector3f(1.165f, 6.08f, 0.025f), rotation, this, false);
                        break;

                }
                break;
            case ATTACHED:
                switch(type){
                    case AWAY_AWAY:
                        sides = new PedestrianWalkSignalSide[2];
                        sides[0] = new PedestrianWalkSignalSide(PedestrianWalkSignalSide.Type.MAIN, PedestrianWalkSignalSide.Orientation.AWAY, assetManager, new Vector3f(.028f, 7.535f, 1.5f), rotation, this, false);
                        sides[1] = new PedestrianWalkSignalSide(PedestrianWalkSignalSide.Type.SECONDARY, PedestrianWalkSignalSide.Orientation.AWAY, assetManager, new Vector3f(2.51f, 7.535f, -0.71f), rotation, this, true);
                        break;

                }
                break;
        }

        parentNode.attachChild(node);
    }

    public TrafficLight getControllingSignal() {
        return controllingSignal;
    }

    public void setControllingSignal(TrafficLight controllingSignal) {
        this.controllingSignal = controllingSignal;
    }

    public Material getMaterial() {
        return material;
    }

    public void setMaterial(Material material) {
        this.material = material;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Node getNode() {
        return node;
    }

    public void setNode(Node node) {
        this.node = node;
    }

    public Node getParentNode() {
        return parentNode;
    }

    public void setParentNode(Node parentNode) {
        this.parentNode = parentNode;
    }

    public PedestrianWalkSignalSide[] getSides() {
        return sides;
    }

    public void setSides(PedestrianWalkSignalSide[] sides) {
        this.sides = sides;
    }

    public Spatial getSpatial() {
        return spatial;
    }

    public void setSpatial(Spatial spatial) {
        this.spatial = spatial;
    }

    public Model getModel() {
        return model;
    }

    public void setModel(Model model) {
        this.model = model;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }
}
